package br.com.escola;

import java.util.HashMap;
import java.util.Map;

import br.com.escola.util.FileUtil;

public class InserirAluno
{
	public static void main(String[] args)
	{
		try
		{
			Map<String, String[]> mAlunos = new HashMap<String, String[]>();
			StringBuffer          sb      = new StringBuffer();
			String                unidade = "e:/";
			String                dataArq = "2013-03-13";

			for (String s : FileUtil.pegaURL(unidade + "_escola/conta-corrente/boletos/boletos" + dataArq + ".csv", "\n").split("\n"))
			{
				String[] c = s.split(";");

				mAlunos.put(c[1], c);
			}

			sb.append("<%@page import=\"br.com.colegio.dao.AlunoDAO\"%>\n<%\n");

			for (String k : mAlunos.keySet())			
				sb.append("AlunoDAO.save(\"" + mAlunos.get(k)[1].replaceAll("'", "").trim() + "\", \"" +
						mAlunos.get(k)[0].replaceAll("'", "").trim() + "\", null, \"" +
						mAlunos.get(k)[2].replaceAll("'", "").trim() + "\");\n");

			sb.append("out.print(\"OK\");\n%>");

			FileUtil.write(unidade + "_escola/conta-corrente/boletos/carga/insert-alunos-" + dataArq + ".jsp", sb.toString());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}
